package com.happe.foodeasy.winter;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * This class will run after spring container has instantiated, and
 * generate tables in database use corresponding class.
 * Created by wubin on 2016-05-18.
 */
@Component
public class TableOperatorPostProcessor implements BeanPostProcessor{
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof TableOperator){
            TableOperator tableOperator = (TableOperator)bean;
            tableOperator.createAllTablesForEntities();
        }
        return bean;
    }
}
